﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ListRead : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—简历管理：您已经购买的简历  {0}", Application["webname"].ToString());
                }
                int enterprise_bid = -1;

                if (Session["enterprise_bid"] != null)
                {
                    enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                    Bind(enterprise_bid);

                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }
        }

        private void Bind(int enterprise_bid)
        {
            int count = 0;
            int recordCount = 0;

            lcmyjobs.BLL.enterprise_read em = new lcmyjobs.BLL.enterprise_read();

            DataSet ds = em.GetRead(enterprise_bid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);
            DataSet ds_totaldel = em.GetList(" isbrowse=1 and enterprise_bid=" + enterprise_bid);//已删除的购买简历

            if (ds.Tables[1].Rows.Count > 0)
            {
                this.lbl_title.Text = " " + ds.Tables[1].Rows[0]["name"].ToString();
                this.lbl_count.Text = count.ToString();
                this.lbl_countdel.Text = ds_totaldel.Tables[0].Rows.Count.ToString();
            }



            if (!string.IsNullOrEmpty(this.lbl_countdel.Text))
            {
                recordCount = count - Convert.ToInt32(this.lbl_countdel.Text);
            }
            this.AspNetPager1.RecordCount = recordCount;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            int enterprise_bid = -1;
            if (Session["enterprise_bid"] != null)
            {
                enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                Bind(enterprise_bid);

            }
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)this.GridView1.Rows[i].FindControl("cbo_rid");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }

        //批量更改用户读取状态为已读
        protected void lbn_delete_Click(object sender, EventArgs e)
        {
            lcmyjobs.BLL.enterprise_read bll = new BLL.enterprise_read();
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length != 0)
            {
                if (bll.UpdateWhere("isbrowse", "1", idlist))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "删除成功！", "ListRead.html");
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请选择所要删除的简历！", "ListRead.html");
            }


        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_read_id = Convert.ToInt32(e.CommandArgument);

                    lcmyjobs.BLL.enterprise_read er = new BLL.enterprise_read();

                    if (er.UpdateWhere("isbrowse", "1", enterprise_read_id.ToString()))
                    {
                        //Maticsoft.Common.MessageBox.ShowAndRedirect(this, "删除成功！", "ListCollection.html");
                        int enterprise_bid = -1;

                        if (Session["enterprise_bid"] != null)
                        {
                            enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                            Bind(enterprise_bid);

                        }
                    }

                }

            }
        }

    }
}